package cn.virens.common.util.components.pool;

import org.apache.commons.pool2.DestroyMode;
import org.apache.commons.pool2.PooledObject;

public interface VirObjectPoolFactory<K, V> {
    /**
     * 根据KEY值创建对应的对象
     *
     * @param key KEY值
     * @return
     * @throws Exception
     */
    public V makeObject(K key) throws Exception;

    /**
     * 验证对象是否有效
     *
     * @param key   KEY值
     * @param value 对象包装
     * @return
     */
    public boolean validateObject(K key, PooledObject<V> value);

    /**
     * 激活对象
     *
     * @param key   KEY值
     * @param value 对象包装
     * @throws Exception
     */
    public void activateObject(K key, PooledObject<V> value) throws Exception;

    /**
     * 冻结对象
     *
     * @param key   KEY值
     * @param value 对象包装
     * @throws Exception
     */
    public void passivateObject(K key, PooledObject<V> value) throws Exception;

    /**
     * 对象销毁事件
     *
     * @param key   KEY值
     * @param value 对象包装
     * @param mode  销毁类型
     * @throws Exception
     */
    public void destroyObject(K key, PooledObject<V> value, DestroyMode mode) throws Exception;
}
